package com.sanjiahantang.youjiaclient.module.invoice.views.impl;

import android.content.Intent;
import android.support.annotation.IdRes;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.sanjiahantang.youjiaclient.R;
import com.sanjiahantang.youjiaclient.base.BaseMvpActivity;
import com.sanjiahantang.youjiaclient.module.invoice.presenters.InvoicePresenter;
import com.sanjiahantang.youjiaclient.module.invoice.views.InvoiceView;


/**
 * Created by admin on 2017/7/25.
 */

public class InvoiceActivity extends BaseMvpActivity<InvoiceView,InvoicePresenter> implements InvoiceView, View.OnClickListener, RadioGroup.OnCheckedChangeListener {
    private RadioGroup radioGroup;
    private View llInvoiceTaxNo;
    private EditText etTitle,etTaxNo;
    String taxNo = null;
    private RadioButton rbInvoicePersonal,rbInvoiceCompany;
    private float money;
    private String orderCode;
    private String isPersonalOrCompany;
    private int orderType;//1 服务 0 商品
    @Override
    public InvoicePresenter initPresenter() {
        return new InvoicePresenter();
    }

    @Override
    public void initData() {
    }


    public void initTitle() {
        TextView title = (TextView) findViewById(R.id.title);
        title.setText("发票信息");
        findViewById(R.id.fl_Left).setOnClickListener(this);
        View save = findViewById(R.id.flIcon3);
        save.setVisibility(View.VISIBLE);
        save.setOnClickListener(this);
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_invoice);
        initTitle();

        radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
        llInvoiceTaxNo = findViewById(R.id.llInvoiceTaxNo);
        etTitle = (EditText) findViewById(R.id.etTitle);
        etTaxNo = (EditText) findViewById(R.id.etTaxNo);
        llInvoiceTaxNo.setVisibility(View.GONE);
        radioGroup.setOnCheckedChangeListener(this);
        rbInvoicePersonal= (RadioButton) findViewById(R.id.rbInvoicePersonal);
        rbInvoiceCompany= (RadioButton) findViewById(R.id.rbInvoiceCompany);

        money = getIntent().getFloatExtra("money",0);
        orderCode = getIntent().getStringExtra("orderCode");
        orderType = getIntent().getIntExtra("orderType",0);
        isPersonalOrCompany = "0";
    }



    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.fl_Left:
                finish();
                break;
            case R.id.flIcon3:

                presenter.saveInvoiceInfoPhoneForCustomer($this,
                        isPersonalOrCompany,
                        etTitle.getText().toString(),
                        etTaxNo.getText().toString(),
                        orderCode,
                        money,
                        orderType,
                        new OnLoadListener() {
                            @Override
                            public void onLoad(Object content) {
                                setResult(RESULT_OK);
                                finish();
                            }
                        });

                break;
        }

    }

    @Override
    public void showProgress() {
        super.showProgress($this);
    }

    @Override
    public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
        switch (checkedId){
            case R.id.rbInvoicePersonal:
                llInvoiceTaxNo.setVisibility(View.GONE);
                etTaxNo.setText("");
                isPersonalOrCompany ="0";
                break;
            case R.id.rbInvoiceCompany:
                etTaxNo.setText(taxNo);
                isPersonalOrCompany ="1";
                llInvoiceTaxNo.setVisibility(View.VISIBLE);
                break;
        }
    }
}
